import request from '@/utils/request'
import menus from '@/router/modules/menu'

//user----start
export function userList(query) {
  return request({
    url: '/user/list',
    method: 'get',
    params: query
  })
}

export function userCreate(data) {
  return request({
    url: '/user/create',
    method: 'post',
    data
  })
}

export function userUpdate(data) {
  return request({
    url: '/user/update',
    method: 'post',
    data
  })
}

export function userDelete(data) {
  return request({
    url: '/user/delete',
    method: 'post',
    data
  })
}

export function userRoleUpdate(data) {
  return request({
    url: '/user/roleUpdate',
    method: 'post',
    data
  })
}

export function userAppUpdate(data) {
  return request({
    url: '/user/appUpdate',
    method: 'post',
    data
  })
}

export function userRoleList(data) {
  return request({
    url: '/user/roleList',
    method: 'post',
    data
  })
}

export function userAppList(data) {
  return request({
    url: '/user/appList',
    method: 'post',
    data
  })
}
//user----end

//permission----start
export function permissionList(query) {
  return request({
    url: '/permission/list',
    method: 'get',
    params: query
  })
}

export function permissionCreate(data) {
  return request({
    url: '/permission/create',
    method: 'post',
    data
  })
}

export function permissionUpdate(data) {
  return request({
    url: '/permission/update',
    method: 'post',
    data
  })
}

export function permissionDelete(data) {
  return request({
    url: '/permission/delete',
    method: 'post',
    data
  })
}

export function permissionTree(data) {
  return request({
    url: '/permission/tree',
    method: 'post',
    data
  })
}

export function permissionRoleUpdate(data) {
  return request({
    url: '/role/permissionUpdate',
    method: 'post',
    data
  })
}
//permission----end

//role----start
export function roleList(query) {
  return request({
    url: '/role/list',
    method: 'get',
    params: query
  })
}

export function roleCreate(data) {
  return request({
    url: '/role/create',
    method: 'post',
    data
  })
}

export function roleUpdate(data) {
  return request({
    url: '/role/update',
    method: 'post',
    data
  })
}

export function roleDelete(data) {
  return request({
    url: '/role/delete',
    method: 'post',
    data
  })
}
//role----end

export function parseTree(routes, node, owns) {

  node.forEach(item => {
    if(item.type == 0 && owns.includes(item.id+"")){
      const menu = {
        path: "/"+item.url,
        component: menus.get(item.url),
        children: [],
        name: item.name,
        meta: { title: item.description, icon: '', noCache: (item.cache == 0) }
      }
      if(item.pid == 0){
        menu.redirect = 'noRedirect'
        menu.meta.icon = item.icon
      }
      if (item.children) {
        parseTree(menu.children, item.children, owns)
      }
      routes.push(menu)
    }
  })

}

//商户----start
export function companyList(query) {
  return request({
    url: '/company/list',
    method: 'get',
    params: query
  })
}

export function companyCreate(data) {
  return request({
    url: '/company/create',
    method: 'post',
    data
  })
}

export function companyUpdate(data) {
  return request({
    url: '/company/update',
    method: 'post',
    data
  })
}

export function companyDelete(data) {
  return request({
    url: '/company/delete',
    method: 'post',
    data
  })
}
//商户----end

//应用----start
export function appList(query) {
  return request({
    url: '/app/list',
    method: 'get',
    params: query
  })
}

export function appCreate(data) {
  return request({
    url: '/app/create',
    method: 'post',
    data
  })
}

export function appUpdate(data) {
  return request({
    url: '/app/update',
    method: 'post',
    data
  })
}

export function appDelete(data) {
  return request({
    url: '/app/delete',
    method: 'post',
    data
  })
}
//应用----end









